package com.photoeditor.demo.ui.widget.image.emoji;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.photoeditor.R;
import com.photoeditor.demo.model.image.emoji.LocalStickerData;
import com.photoeditor.demo.model.image.emoji.StickerCategoryBean;
import com.photoeditor.demo.ui.widget.CheckableImageView;


/**
 * emoji单个ITEM 的View
 */
public class EmojiCheckableItem extends RelativeLayout {

    private String mPkgName;
    private CheckableImageView mIcon;
    private ImageView mVipIcon;

    public EmojiCheckableItem(Context context) {
        super(context);
        initView();
    }

    private void initView() {
        LayoutInflater.from(getContext()).inflate(R.layout.item_emoji_checkable, this, true);
        mIcon = (CheckableImageView) findViewById(R.id.emoji_button);
        mVipIcon = findViewById(R.id.img_vip);
    }

    public String getPackageName() {
        return mPkgName;
    }

    /**
     * @param categoryBean 贴纸类别
     */
    public void setPackageName(StickerCategoryBean categoryBean) {
        this.mPkgName = categoryBean.getPkgName();
        try {
            LocalStickerData.getInstance().getButtonIcon(categoryBean, this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setBgCheckDrawable(Drawable bgDrawable, Drawable bgCheckDrawable) {
        mIcon.setBackgroundDrawable(bgDrawable, bgCheckDrawable);
    }

    public void setChecked(boolean isChecked) {
        mIcon.setChecked(isChecked);
    }

    public void setVip(boolean isVip) {
        if (isVip) {
            mVipIcon.setVisibility(VISIBLE);
        } else {
            mVipIcon.setVisibility(GONE);
        }
    }

    public ImageView getImageView() {
        return mIcon;
    }

}
